import filters from "./filters.js";

export default {
	/**
	 * 不需要登录就跳转的
	 */
	go(url, type = "navigateTo") {
		this.goURL(url, type);
	},
	/**
	 * 需要登录才能跳转
	 */
	to(url, type = "navigateTo") {
		if (!filters.isLogin()) {
			return;
		}
		this.goURL(url, type);
	},
	/**
	 * 跳转
	 */
	reTo(url) {
		this.goURL(url, "redirectTo");
	},
	/**
	 * 跳转
	 */
	goURL(url, type = "navigateTo") {
		if (url === "") {
			return;
		}
		var tabList = [
			"/pages/tabBar/home",
			"/pages/tabBar/shopping",
			"/pages/tabBar/message",
			"/pages/tabBar/cart",
			"/pages/tabBar/mine",
		];
		
		if (tabList.indexOf(url) > -1) {
			uni.switchTab({
				url: url,
			});
		} else {
			if (type === "navigateTo") {
				uni.navigateTo({
					url: url,
				});
			} else if (type === "redirectTo") {
				uni.redirectTo({
					url: url,
				});
			}
		}
	},
	/**
	 * 返回
	 */
	back(num = 1) {
		uni.navigateBack({
			delta: num
		})
	},
	/**
	 * 登录
	 */
	login() {
		filters.isLogin();
	},
	
	/**
	 * htmlweb页面
	 */
	goHTMLWeb(title, name, id = "") {
		this.go(`/pages/webView/htmlWebView?title=${title}&name=${name}&id=${id}`);
	},
	/**
	 * 跳转到商品详情
	 */
	onGoodsDetail(goods_id) {
		this.to(`/pages/product/goods?id=${goods_id}`)
	},
	/**
	 * 店铺页面
	 */
	onStoreIndex(store_id) {
		this.to(`/pages/shop/index?id=${store_id}`)
	},
	/**
	 * 文章详情
	 */
	onArticleDetail(article_id, other = "") {
		this.to(`/pages/home/article/details?id=${article_id}${other}`)
	},
	/**
	 * 订单详情
	 */
	
	
	/**
	 * 支付成功页面
	 */
	paySuccess(type, other = '') {
		this.to(`/pages/common/success?type=${type}${other}`, "redirectTo");
	},
	/**
	 * 去支付
	 */
	goPay(token, data, other = "") {
		this.to(`/pages/user/money/pay?token=${token}&data=${JSON.stringify(data)}${other}`);
	}
}